<?php
		include("global.php");
                printHeader(false);
                session_start();
                
                $NUMERI_TELEFONO=$_SESSION['NUMERI_TELEFONO'];
                $DATA_TABLE=$_SESSION['DATA_TABLE'];
                $LISTA_ALR_ENABLE_SMS=$_SESSION['LISTA_ALR_ENABLE_SMS'];
                $HOUR_IN_A_DAY=$_SESSION['HOUR_IN_A_DAY'];
		$key = @urldecode($_GET["skey"]);
		if(!preg_match("/(...) (..:..)/",$key,$matches))
		{
			
			exit;
		}
		$d = $matches[1];
                $h = $matches[2];
		$ld = $DAY_OF_WEEK_LONG[array_search($d,$DAY_OF_WEEK)];
		$superkey = $d . " " .$h;
//                
		?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
    <head>
         
        <style>
          body {
                        text-align: left;
                }
          select {
                width: 208px;
                color: #555;
                padding: 4px 4px 3px;
                border: 2px solid #B5B8C8;
                font-size: 14px;
                margin-top: 4px;
                margin-bottom: 4px;
                background: #FFFFFF;

                }
            div.message{padding: 15px 10px 0 50px;border: solid;border-width: 2px 0;background:#F0F0F0}
            div.message p{margin: 0 0 1em}
            div.message.warning{background: #FFF0BA url(img/warning20.png) no-repeat 20px 3px;border-color: #E87C29; 
                                width: 450px;float:left;}

         </style>
        <script type="text/javascript">
                var operazione;
                var num_select_op=new Array();
                num_select_op['del']=0;
                num_select_op['add']=0;
                
                $(document).ready(function() {
                // se il checkbox è selezionato coloro la label per simulare la colorazione delle select
                $('#jqmultiselect label').each(function() {
                if ($(this).find(':checkbox').attr('checked')) 
                    $(this).addClass('selected');
                });
                // al click sul checkbox metto/tolgo la classe 'selected'
                $('#jqmultiselect :checkbox').click(function(e) {
                var checked = $(this).attr('checked');
                $(this).closest('label').toggleClass('selected', checked);
                });
                });
                
                function selectCkeck(ob,op)
                {
                    
                   if(ob.checked)
                       num_select_op[op]++;
                   else
                       num_select_op[op]--;
                    
                }
                
                
        </script>

        <script src="files/js/jquery-1.3.min.js" type="text/javascript"></script>
       
        
       
            
        <link media="screen" type="text/css" href="style/form.css" rel="stylesheet" />
	<link media="screen" type="text/css" href="style/formcheck.css" rel="stylesheet" /> 
        <link rel="stylesheet" type="text/css" href="./style/button.css" />
        <style type="text/css">
            ul#jqmultiselect {
            border: 1px solid #A5A8B8;
            height: 90px;
            list-style: none outside none;
            overflow-x: hidden;
            overflow-y: auto;
            padding: 0;
            width: 628px;
            background-color: #ffffff;
            }
            #jqmultiselect li label {
            color: #000000;
            display: block;
            outline: medium none;
            padding: 4px 4px 4px 26px;
            position: relative;
            }
            #jqmultiselect li label:hover {
            background-color: #b1a9a9;
            color: #000000;
            }
            #jqmultiselect li label.selected {
            background-color: #d0cece;
            color: #9A9191;
            }
            #jqmultiselect li label .checkbox {
            left: 2px;
            position: absolute;
            top: 2px;
            }
        </style>
       
    </head>
    
    <body>
        <form method="post" action="files/php/caloperation.php" class="formular" id="formular">
                
	<?php 
        if(sizeof($NUMERI_TELEFONO) >= 1)
        {
            
        ?>  
        <h2>Intervalli orari del giorno <?php print $ld?></h2>
                    <?php 
                    if(sizeof($DATA_TABLE[$superkey]) >= 1)
                    {
                        $arr_enabled=array();
                    ?>
                
                 <fieldset> 	
                     <legend>Elimina Disponibilit&agrave; Cellulari</legend>
                           <label for="lista">Nome - Numero - Allarme </label>
                           <ul id="jqmultiselect">
                             <?php 
                                            foreach($DATA_TABLE[$superkey] as $i => $tel)
                                            {
                                                    print("<li>
                                                        <label for=\"idAlarms_$i\">
                                                        ");
                                                    
                                                    $arr_enabled[$tel[2]]=$tel[2];
                                                    
                                                    //$t = urlencode($tel[1]);
                                                    //$idAllarm = urlencode($tel[2]);
                                                    //$url =("operation=del&day=$d&begindate=$h&enddate=$h&phone=$t&id_allarm=$idAllarm");
                                                   // $id_table="$tel[0]:$tel[1]:$tel[2]";
                                                    print('<input type="checkbox" name="idAlarms[]" id="cinema" value="'.$tel[4].'" class="checkbox" onClick="javascript:selectCkeck(this,\'del\');"/>');
                                                        
                                                    print("$tel[0] - $tel[1] - $tel[2]:$tel[3]</label>
                                                    </li>    
                                                    ");
                                                    
                                            }
                                   ?>
                               
                            </ul>
                            <div id="warningElimina"></div>
                            <div class="buttonElimina">
                                 
<!--                            <button type="submit" name="mySubmit" id="submit" value="Visualizza" style="margin: 0px 0 0 8px;" class="buttonview" /> <span id="msgbox" style="display:none"></span>Visualizza</button>-->
                            <input type="button" value="Elimina" style="margin: 0px 0 0 527px;" class="buttongloreset" onClick="javascript:invioForm('del');"/>
                            </div>
                            
                            
                    </fieldset>
                    <?php 
                    } 
                    ?>
                
                    <fieldset> 
		    <legend>Aggiungi Disponibilit&agrave; Cellulari</legend>
                 	
			<input type="hidden" name="day" value="<?php print $d;?>"></input>
			<input type="hidden"  id="operation" name="operation" value=''/>
			<table id="visualizza">
                            <tr>
                                <td>
                                   <label for="begindate">Data Inizio</label>
                                   <select name="begindate">
                                            <?php print "<option value=\"$h\">$h</option>"?>

                                   </select>
                                </td>
                                <td>
                                   <label for="enddate">Data Fine</label>
                                   <select name="enddate">
                                                        <?php
                                                                $p = 0;
                                                                                foreach($HOUR_IN_A_DAY as $i => $v)
                                                                                {
                                                                                        if($v > $h)
                                                                                                {
                                                                                                        $p = 1;
                                                                                                }
                                                                                        if($p)
                                                                                                {
                                                                                                        print "<option value=\"$v\">$v</option>";
                                                                                                }

                                                                                }
                                                        ?>
                                   </select>
                                </td>
                                <td>
                                    <label for="phone">Telefono</label>
                                    <select name="phone">
                                            <?php 
                                                    foreach($NUMERI_TELEFONO as $i => $tel)
                                                            print("<option value=\"$i\">$tel - $i</option>");

                                                    ?>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    <label for="phone">ID Allarme</label>
                                 
                                    <ul id="jqmultiselect">
                                    <?php 
                                        foreach($LISTA_ALR_ENABLE_SMS as $i => $tel)
                                        {
                                           // if($arr_enabled[$i]!=$i)
                                           // {
                                            print("<li>
                                            <label for=\"enableAlarms_$i\">
                                            ");
                                            print('<input type="checkbox" name="idAlarms[]" id="cinema" value="'.$i.'" class="checkbox" onClick="javascript:selectCkeck(this,\'add\');"/>');
                                            print("$i - $tel</label></li>");
                                          //  }
                                        }
                                    ?>

                                    </ul>
                                </td>
                            </tr>

                        </table>
                        <div id="warningAdd"></div>
                        <div class="buttonAggiungi">
<!--                            <button type="submit" name="mySubmit" id="submit" value="Visualizza" style="margin: 0px 0 0 8px;" class="buttonview" /> <span id="msgbox" style="display:none"></span>Visualizza</button>-->
                            <input type="button" value="Aggiungi" style="margin: 0px 0 0 527px;" class="buttonview"  onClick="invioForm('add');"/>
                            </div>
                        
                        
                 </fieldset>
        
            </form>
        
	<?php
        }
        else
        {
        ?>
            <h4>Non sono presenti numeri Telefonici per inserire intervalli orari.<br/> Bisogna prima inserire un numero di Telefono in rubrica al <br/> <a href="Rubrica.php">Aggiungi</a></h4>
        <?php 
        }
        ?>
</body>
    
    <script type="text/javascript">
function invioForm(op)
{
    
    if( (num_select_op[op] <= 0))
    {
        if("add" == op)
        {
            
            $("#warningAdd").attr('class', 'message warning');
            $("#warningAdd").html("Attenzione: bisogna selezionare almeno un allarme");
        }
        else
        {
            
            $("#warningElimina").attr('class', 'message warning');
            $("#warningElimina").html("Attenzione: Bisogna selezionare almeno un numero da eliminare");
        
        }
    }
    else 
    {
        document.getElementById('operation').value=op;
        document.forms['formular'].submit(); 
    }
}   
</script>

</html>